var ds, subKeyword;
var selectKeyCache = '';
var clearSelectKeyCache = true;
function displayKeySubject() {
	Ext.form.Field.prototype.msgTarget = 'side';
	Ext.QuickTips.init();
	var sm = new Ext.grid.RowSelectionModel({
		singleSelect : true
	});
	ds = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : DISPATCH_URL
		}),
		reader : new Ext.data.JsonReader({
			root : 'keysubjects',
			totalProperty : 'totalCount',
			id : 'id',
			fields : [ {
				name : 'id'
			}, {
				name : 'name'
			}, {
				name : 'keywords'
			}, {
				name : 'must'
			}, {
				name : 'p_type'
			} ]
		})
	});
	var gridCm = new Ext.grid.ColumnModel([
			new Ext.grid.RowNumberer(),
			{
				header : TXT_keysubject_name,
				dataIndex : 'name',
				width : 130,
				renderer : function(value, metadata, record) {
					if (value.length > 7)
						return '<a HREF="javascript:searchTest(\''
								+ record.get('id') + '\')"><div qtip=' + value
								+ '>' + value.substring(0, 7) + '</div></a>';
					else
						return '<a HREF="javascript:searchTest(\''
								+ record.get('id') + '\')">' + value + '</a>';
				}
			},
			{
				header : TXT_keysubject_keywords,
				dataIndex : 'keywords',
				width : 333,
				renderer : function(v, md, r) {
					if (v.length > 17)
						return '<div qtip=' + v + '>' + v.substring(0, 17)
								+ '</div>';
					else
						return v;
				}
			},
			{
				header : TXT_keysubject_must,
				dataIndex : 'must',
				width : 333,
				renderer : function(v, md, r) {
					if (v.length > 17)
						return '<div qtip=' + v + '>' + v.substring(0, 17)
								+ '</div>';
					else
						return v;
				}
			},
			{
				header : TXT_p_type,
				dataIndex : 'p_type',
				width : 80,
				renderer : function(v, md, r) {
					if (v.length > 5)
						return '<div qtip=' + v + '>' + v.substring(0, 5)
								+ '</div>';
					else
						return v;
				}
			} ]);
	var siteDs = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : DISPATCH_URL
		}),
		reader : new Ext.data.JsonReader({
			root : 'sites',
			id : 'id',
			fields : [ {
				name : 'id'
			}, {
				name : 'name'
			}, {
				name : 'code'
			} ]
		})
	});
	var siteCombo = new Ext.form.ComboBox({
		id : 'siteCb',
		name : 'siteCb',
		mode : 'local',
		forceSelection : true,
		displayField : 'name',
		valueField : 'code',
		emptyText : '--切换驻地--',
		width : 90,
		triggerAction : 'all',
		selectOnFocus : true,
		triggerClass : 'x-form-trigger2',
		store : siteDs,
		lazyInit : false,
		editable : false
	});
	siteCombo.on('select', function(combo, record, index) {
		ds.load({
			params : {
				start : 0,
				limit : PAGE_SIZE,
				siteCode : record.get('code')
			}
		});
		BestvSearch.sc = record.get('code');
	});
	siteDs.baseParams = {
		cmd : 'site',
		action : 'find'
	};
	var btnCreate = new Ext.Button({
		text : TXT_common_create,
		tooltip : TXT_common_create,
		iconCls : 'icoAdd'
	});
	btnCreate.on('click', function() {
		createKeySubjectForm('');
	});
	var btnEdit = new Ext.Button({
		text : TXT_common_edit,
		tooltip : TXT_common_edit,
		iconCls : 'icoDetail'
	});
	btnEdit.on('click', function() {
		if (sm.getCount() == 0) {
			Ext.MessageBox.alert(TXT_common_hint, TXT_user_need);
			return;
		}
		var record = sm.getSelected();
		createKeySubjectForm(record.id);
	});
	var btnDelete = new Ext.Button({
		text : TXT_common_delete,
		tooltip : TXT_common_delete,
		iconCls : 'icoDel'
	});
	btnDelete
			.on(
					'click',
					function() {
						if (sm.getCount() == 0) {
							Ext.MessageBox
									.alert(TXT_common_hint, TXT_user_need);
							return;
						}
						var record = sm.getSelected();
						Ext.MessageBox
								.confirm(
										TXT_common_hint,
										TXT_user_delete_confirmation,
										function(btn) {
											if (btn == 'yes') {
												BestvSearch.showWaitingWin();
												Ext.Ajax
														.request({
															url : DISPATCH_URL,
															method : 'POST',
															params : 'cmd=keysubject&action=delete&id='
																	+ record.id
																	+ '&sc='
																	+ BestvSearch.sc,
															success : function(
																	response,
																	options) {
																Ext.MessageBox
																		.hide();
																var s = response.responseText;
																if (s == '[error]') {
																	Ext.MessageBox
																			.alert(
																					TXT_common_hint,
																					TXT_common_access_fail);
																} else if (s == '[null]') {
																	Ext.MessageBox
																			.alert(
																					TXT_common_hint,
																					TXT_common_relogin,
																					function() {
																						window.location.href = LOGIN_URL;
																					});
																} else {
																	var result = Ext.util.JSON
																			.decode(s);
																	if (result.result == 'success') {
																		ds
																				.load({
																					params : {
																						start : 0,
																						limit : PAGE_SIZE,
																						siteCode : BestvSearch.sc
																					}
																				});
																	} else if (result.message == 'noright') {
																		Ext.MessageBox
																				.alert(
																						TXT_common_hint,
																						TXT_delete_subtype_no_right);
																		return;
																	}
																}
															},
															failure : function(
																	response,
																	options) {
																Ext.MessageBox
																		.hide();
																Ext.MessageBox
																		.alert(
																				TXT_common_hint,
																				TXT_common_access_fail);
															}
														});
											}
										});
					});
	var grid = new Ext.grid.GridPanel(
			{
				el : 'grid',
				ds : ds,
				cm : gridCm,
				sm : sm,
				stripeRows : true,
				loadMask : true,
				title : TXT_key_subject_title,
				tbar : [ btnCreate, '-', btnEdit, '-', btnDelete, '->',
						siteCombo, '-' ],
				viewConfig : {
					forceFit : true
				},
				bbar : new Ext.PagingToolbar({
					pageSize : PAGE_SIZE,
					store : ds,
					displayInfo : true,
					displayMsg : TXT_common_paging,
					emptyMsg : TXT_common_no
				})
			});
	ds.baseParams = {
		cmd : 'keysubject',
		action : 'find'
	};
	ds.on('load', function() {
		grid.getSelectionModel().selectLastRow();
	});
	// ds.load({params:{start:0,limit:PAGE_SIZE,siteCode:BestvSearch.sc}});
	BestvSearch.glb_mainPanel.add(grid);
	BestvSearch.drawMainFrame(TXT_app_name + ' - ' + TXT_key_subject_title,
			siteDs);
	siteDs.on('load', function() {
		siteCombo.setValue(BestvSearch.sc);
		ds.load({
			params : {
				start : 0,
				limit : PAGE_SIZE,
				siteCode : BestvSearch.sc
			}
		});
		siteCombo.setDisabled(true);
	});
}
function searchTest(value) {
	var record = ds.getById(value);
	var keys = record.get('keywords');
	var must = record.get('must');
	var ptype = record.get('p_type');
	// window.open(encodeURI('./preview.htm?q='+keys+'&'+ptype));
	window.location.href = encodeURI('./preview.htm?q=' + keys + '&' + must
			+ '&' + ptype + '&' + BestvSearch.sc);
}
function createKeySubjectForm(subId) {
	var sc = BestvSearch.sc;
	var sid = subId;
	var pTypeDs = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : DISPATCH_URL
		}),
		reader : new Ext.data.JsonReader({
			root : 'p_types',
			id : 'id',
			fields : [ {
				name : 'id'
			}, {
				name : 'name'
			} ]
		})
	});
	pTypeDs.baseParams = {
		'cmd' : 'bizType',
		'action' : 'findBizTypes'
	};
	pTypeDs.on('loadexception', function() {
	});
	var pTypeCombo = new Ext.form.ComboBox({
		fieldLabel : '<b style="color:red;">* </b>分 类',
		id : 'pType',
		name : 'pType',
		mode : 'local',
		displayField : 'name',
		emptyText : '选择分类...',
		valueField : 'id',
		typeAhead : true,
		triggerAction : 'all',
		selectOnFocus : true,
		triggerClass : 'x-form-trigger2',
		store : pTypeDs,
		lazyInit : false,
		editable : false,
		allowBlank : false
	});
	subKeyword = new Ext.form.TextField(
			{
				fieldLabel : '<b style="color:red;">* </b> 对应"关联搜索词库"',
				emptyText : '输入关键字，"回车"添加到"关键字预览/编辑"框，多个关键字空格隔开',
				id : 'subKeywords',
				name : 'subKeywords',
				allowBlank : true,
				listeners : {
					specialkey : function(field, e) {
						if (e.getKey() == e.ENTER) {
							if (field.getValue() == '')
								return;
							var values = field.getValue().split(' ');
							for ( var t = 0; t < values.length; ++t) {
								if (values[t] == ''
										|| document.getElementById('s_'
												+ values[t]) != null)
									continue;
								var keybody = document
										.getElementById('selectKeys').innerHTML;
								keybody += '<span id=\'s_'
										+ values[t]
										+ '\'><u>'
										+ values[t]
										+ '<span class="delXO hV hM" onclick="deleteKey(\''
										+ values[t]
										+ '\')" style="background-color: rgb(238, 238, 238); color: rgb(34, 34, 34);"><span class="hO" title="删除">X</span></span></u></span>';
								document.getElementById('selectKeys').innerHTML = keybody;
								selectKeyCache += '/&' + values[t] + '/&';
							}
							field.setValue(' ');
						}
					},
					blur : function(field) {
						field.setValue('');
					}
				}
			});
	var keyPanel = new Ext.Panel(
			{
				html : '<div style="line-height:1.4;font-weight:normal;font-style:normal;font-size:small;"></div><div style="height:8px;"></div><table><tr><td style="width:8px"></td><td id="selectKeys"></td><td style="width:8px"></td></tr></table>',
				title : '关键字预览/编辑',
				autoScroll : true,
				// layout:'fit',
				region : 'south',
				border : true,
				height : 280
			});
	var btnSelect = new Ext.Button({
		text : TXT_common_select,
		tooltip : TXT_common_select,
		iconCls : 'icoImport',
		listeners : {
			click : searchKeys
		}
	});
	var subjectForm = new Ext.FormPanel({
		labelAlign : 'right',
		border : false,
		region : 'center',
		labelWidth : 125,
		frame : true,
		height : 118,
		width : 644,
		items : [ {
			layout : 'column',
			items : [ {
				columnWidth : .5,
				layout : 'form',
				defaultType : 'textfield',
				defaults : {
					anchor : '92%'
				},
				items : [ {
					fieldLabel : '<b style="color:red;">* </b> 新增主题词名字',
					id : 'keySubjctName',
					name : 'keySubjctName',
					allowBlank : false
				} ]
			}, {
				columnWidth : .5,
				labelWidth : 45,
				layout : 'form',
				defaultType : 'textfield',
				defaults : {
					anchor : '90%'
				},
				items : [ pTypeCombo ]
			} ]
		}, {
			layout : 'form',
			height : 2
		}, {
			layout : 'form',
			height : 2
		}, {
			layout : 'column',
			items : [ {
				columnWidth : .9,
				layout : 'form',
				defaultType : 'textfield',
				defaults : {
					anchor : '99%'
				},
				items : [ {
					fieldLabel : '搜索必选词',
					emptyText : '必选词之间用空格(" ")或者斜杠("/")隔开',
					id : 'must',
					name : 'must',
					allowBlank : true
				} ]
			} ]
		}, {
			layout : 'column',
			items : [ {
				columnWidth : .46,
				layout : 'form',
				defaultType : 'textfield',
				defaults : {
					anchor : '97%'
				},
				items : [ new Ext.form.DateField({
					fieldLabel : '<b style="color:red;">* </b>生效时间',
					id : 'invalidDate',
					name : 'invalidDate',
					format : "Y-m-d G:i"
				}) ]
			}, {
				columnWidth : .02,
				layout : 'form',
				defaults : {
					anchor : '99%'
				},
				html : '~',
				align : 'center'
			}, {
				columnWidth : .28,
				layout : 'form',
				defaults : {
					anchor : '95%'
				},
				items : [ new Ext.form.DateField({
					hideLabel : true,
					labelWidth : 0,
					id : 'invalidDate2',
					name : 'invalidDate2',
					format : "Y-m-d G:i"
				}) ]
			} ]
		}, {
			layout : 'column',
			items : [ {
				columnWidth : .85,
				layout : 'form',
				defaultType : 'textfield',
				defaults : {
					anchor : '98%'
				},
				items : [ subKeyword ]
			}, {
				columnWidth : .15,
				layout : 'form',
				// html:'<a HREF="javascript:searchKeys()"
				// class="a1"><b>选择</b></a>'
				items : [ btnSelect ]
			} ]
		} ]
	});
	var title;
	if (sid == '')
		title = TXT_key_subject_create;
	else
		title = TXT_key_subject_edit;
	var win = null;
	if (!win) {
		win = new Ext.Window(
				{
					title : title,
					layout : 'form',
					width : 630,
					autoHeigth : true,
					autoScroll : false,
					border : false,
					minimizable : false,
					maximizable : false,
					resizable : false,
					modal : true,
					layoutConfig : {
						animate : false
					},
					items : [ subjectForm, keyPanel ],
					buttonAlign : 'center',
					buttons : [
							{
								text : TXT_common_OK,
								handler : function(response, options) {
									if (!subjectForm.getForm().isValid())
										return;
									if (selectKeyCache == '') {
										Ext.MessageBox.alert(TXT_common_hint,
												'对应"关联搜索词库不能为空"!');
										return;
									}
									var ptypeid = pTypeCombo.getValue();
									// alert(ptypeid);
									var ptypeStr = pTypeDs.getById(ptypeid)
											.get('name');
									// alert(ptypeStr);
									var subjectName = subjectForm.findById(
											'keySubjctName').getValue();
									var keywords = selectKeyCache.substring(2,
											selectKeyCache.length - 2).replace(
											/\/&\/&/g, ' ');
									var must = subjectForm.findById('must')
											.getValue();
									var validDate = Ext.util.Format.date(
											subjectForm.findById('invalidDate')
													.getValue(), 'Y-m-d G:i');
									var validDate2 = Ext.util.Format.date(
											subjectForm
													.findById('invalidDate2')
													.getValue(), 'Y-m-d G:i');
									if (validDate == '' && validDate2 == '') {
										Ext.MessageBox.alert(TXT_common_hint,
												'请选择生效时间!');
										return;
									}
									var dateValid = true;
									if (validDate != '' && validDate2 != '')
										dateValid = subjectForm.findById(
												'invalidDate').getValue() <= subjectForm
												.findById('invalidDate2')
												.getValue();
									if (!dateValid) {
										Ext.MessageBox.alert(TXT_common_hint,
												'生效时间范围不对!');
										return;
									}
									BestvSearch.showWaitingWin();

									Ext.Ajax
											.request({
												url : DISPATCH_URL,
												mehtod : 'post',
												params : 'cmd=keysubject&action=save&id='
														+ sid
														+ '&subjectName='
														+ subjectName
														+ '&ptypeid='
														+ ptypeid
														+ '&ptype='
														+ ptypeStr
														+ '&keywords='
														+ keywords
														+ '&validDate='
														+ validDate
														+ '&invalidDate='
														+ validDate2
														+ '&must='
														+ must + '&sc=' + sc,
												success : function(response,
														options) {
													Ext.MessageBox.hide();
													var s = response.responseText;
													if (s == 'error') {
														Ext.MessageBox
																.alert(
																		TXT_common_hint,
																		TXT_common_access_fail);
													} else if (s == 'null') {
														Ext.MessageBox
																.alert(
																		TXT_common_hint,
																		TXT_common_relogin,
																		function() {
																			window.location.href = '../eni/common/logout.jsp';
																		});
													} else if (s == '[existed]') {
														Ext.MessageBox
																.alert(
																		TXT_common_hint,
																		'相同的主题词已经存在');
													} else {
														var result = Ext.util.JSON
																.decode(s);
														if (result.result == 'success') {
															ds
																	.load({
																		params : {
																			start : 0,
																			limit : PAGE_SIZE,
																			siteCode : sc
																		}
																	});
															win.close();
														}
													}
													selectKeyCache = '';
												},
												failure : function(response,
														options) {
													Ext.MessageBox.hide();
													Ext.MessageBox
															.alert(
																	TXT_common_hint,
																	TXT_common_access_fail);
												}
											});
								}
							}, {
								text : TXT_common_cancel,
								handler : function() {
									selectKeyCache = '';
									win.close();
								}
							} ]
				});
	}
	pTypeDs.load({
		params : {
			siteCode : sc
		}
	});
	win
			.on(
					'show',
					function() {
						if (subId != '') {
							Ext.Ajax
									.request({
										url : DISPATCH_URL,
										mehtod : 'post',
										params : 'cmd=keysubject&action=get&id='
												+ subId + '&sc=' + sc,
										success : function(response, options) {
											var s = response.responseText;
											if (s == '[error]')
												Ext.MessageBox.alert(
														TXT_common_hint,
														TXT_common_access_fail);
											else if (s == '[null]') {
												Ext.MessageBox
														.alert(
																TXT_common_hint,
																TXT_common_relogin,
																function() {
																	window.location.href = LOGIN_URL;
																});
											} else {
												var result = Ext.util.JSON
														.decode(s);
												pTypeCombo
														.setValue(result.ptype);
												subjectForm.findById(
														'keySubjctName')
														.setValue(result.name);
												subjectForm.findById('must')
														.setValue(result.must);
												subjectForm.findById(
														"invalidDate")
														.setValue(result.time);
												subjectForm.findById(
														"invalidDate2")
														.setValue(result.vtime);
												var sk = result.keywords;
												if (sk != '') {
													var sks = sk.split(/ +/);
													var keybody = '';
													for ( var k = 0; k < sks.length; ++k) {
														if (sks[k] == '')
															continue;
														keybody += '<span id=\'s_'
																+ sks[k]
																+ '\'><u>'
																+ sks[k]
																+ '<span class="delXO hV hM" onclick="deleteKey(\''
																+ sks[k]
																+ '\')" style="background-color: rgb(238, 238, 238); color: rgb(34, 34, 34);"><span class="hO" title="删除">X</span></span></u></span>';
														selectKeyCache += '/&'
																+ sks[k] + '/&';
													}
													document
															.getElementById('selectKeys').innerHTML = keybody;
												}
											}
										},
										failure : function(response, options) {
											Ext.MessageBox.alert(
													TXT_common_hint,
													TXT_common_access_fail);
										}
									});
						}
					});
	win.show();
	// pTypeDs.load({params:{siteCode:sc}});
}
function searchKeys() {
	var searchFieldDs = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : DISPATCH_URL
		}),
		reader : new Ext.data.JsonReader({
			root : 'searchFields',
			id : 'id',
			fields : [ {
				name : 'name'
			}, {
				name : 'description'
			} ]
		})
	});
	searchFieldDs.baseParams = {
		cmd : 'searchConfig',
		'action' : 'findForCombo'
	};
	searchFieldCombo = new Ext.form.MultiComboBox({
		id : 'searchFieldCombo',
		name : 'searchFieldCombo',
		editable : false,
		displayField : 'description',
		valueField : 'name',
		labelSeparator : ':',
		displaySeparator : ' ',
		valueSeparator : ' ',
		mode : 'local',
		loadingText : 'loading...',
		store : searchFieldDs,
		hiddenName : 'test',
		triggerAction : 'all',
		emptyText : '可选多个...',
		fieldLabel : '搜索域',
		allowBlank : true
	});
	searchFieldDs.load({
		params : {
			sc : BestvSearch.sc
		}
	});
	var searchTypeDs = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : DISPATCH_URL
		}),
		reader : new Ext.data.JsonReader({
			root : 'types',
			id : 'id',
			fields : [ {
				name : 'id'
			}, {
				name : 'name'
			}, {
				name : 'description'
			} ]
		})
	});
	searchTypeDs.baseParams = {
		cmd : 'type',
		action : 'find'
	};
	searchTypeCombo = new Ext.form.MultiComboBox({
		id : 'searchTypeCombo',
		name : 'searchTypeCombo',
		editable : false,
		displayField : 'description',
		valueField : 'name',
		labelSeparator : ':',
		displaySeparator : ' ',
		valueSeparator : ' ',
		hiddenName : 'test',
		mode : 'local',
		store : searchTypeDs,
		triggerAction : 'all',
		emptyText : '可选多个',
		fieldLabel : '类型'
	});
	searchTypeDs.load({
		params : {
			sc : BestvSearch.sc
		}
	});
	var vtypeDs = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : DISPATCH_URL
		}),
		reader : new Ext.data.JsonReader({
			root : 'p_types',
			fields : [ {
				name : 'name'
			}, {
				name : 'code'
			} ]
		})
	});
	vtypeDs.baseParams = {
		'cmd' : 'keysubject',
		'action' : 'findPType'
	};
	vTypeCombo = new Ext.form.MultiComboBox({
		id : 'vTypeCombo',
		editable : false,
		name : 'vTypeCombo',
		displayField : "name",
		valueField : 'code',
		labelSeparator : ':',
		displaySeparator : ' ',
		valueSeparator : ' ',
		mode : 'local',
		hiddenName : 'test',
		store : vtypeDs,
		triggerAction : 'all',
		emptyText : '可选多个...',
		fieldLabel : '垂直分类'
	});
	vtypeDs.load({
		params : {
			sc : BestvSearch.sc
		}
	});
	timeFrom = new Ext.form.DateField({
		fieldLabel : '时间范围',
		id : 'fromTime',
		name : 'fromTime',
		format : "Y-m-d"
	});
	timeTo = new Ext.form.DateField({
		hideLabel : true,
		labelWidth : 0,
		id : 'timeTo',
		name : 'timeTo',
		format : "Y-m-d"
	});

	var btnFind = new Ext.Button({
		text : TXT_common_search,
		tooltip : TXT_common_search,
		iconCls : 'icoFind'
	});
	btnFind
			.on(
					'click',
					function() {
						if (searchInfoForm.findById('skey').getValue() == '') {
							Ext.MessageBox.alert(TXT_common_hint,
									'输入有误，搜索关键字不能为空');
							return false;
						}
						var json = {
							"keywords" : "",
							"fields" : "",
							"filters" : []
						};
						if (searchTypeCombo.hiddenField.value != '')
							json.filters
									.push({
										"filterField" : "type",
										"filterValue" : searchTypeCombo.hiddenField.value
									});
						if (vTypeCombo.getValue() != '')
							json.filters.push({
								"filterField" : "p_type",
								"filterValue" : vTypeCombo.getValue()
							});
						var filterUpdateTime = 'min TO max';
						var tf = Ext.util.Format.date(timeFrom.getValue(),
								'Y-m-d G:i');
						var tt = Ext.util.Format.date(timeTo.getValue(),
								'Y-m-d');
						if (tt != '')
							tt += ' 23:59';
						if (tf != '') {
							var tfs = tf.split(' ');
							if (tfs.length != 2) {
								Ext.MessageBox.alert(TXT_common_hint,
										'时间格式错误，正确格式为：yyyy-MM-dd HH:mm');
								return false;
							}
							tfs[0] = tfs[0].replace(/-/g, '');
							tfs[1] = tfs[1].replace(':', '');
							if (tfs[1].length == 3)
								tfs[1] = '0' + tfs[1];
							tf = tfs[0] + tfs[1];
							filterUpdateTime = filterUpdateTime.replace("min",
									tf);
						}
						if (tt != '') {
							var tts = tt.split(' ');
							if (tts.length != 2) {
								Ext.MessageBox.alert(TXT_common_hint,
										'时间格式错误，正确格式为：yyyy-MM-dd HH:mm');
								return false;
							}
							tts[0] = tts[0].replace(/-/g, '');
							tts[1] = tts[1].replace(':', '');
							if (tts[1].length == 3)
								tts[1] = '0' + tts[1];
							tt = tts[0] + tts[1];
							filterUpdateTime = filterUpdateTime.replace("max",
									tt);
							if (tt < tf) {
								Ext.MessageBox.alert(TXT_common_hint,
										'时间错误，起始时间应该小于结束时间！');
								return false;
							}
						}
						if (filterUpdateTime !== 'min TO max')
							json.filters.push({
								"filterField" : "updateTime",
								"filterValue" : filterUpdateTime
							});
						json.keywords = searchInfoForm.findById('skey')
								.getValue();
						json.fields = searchFieldCombo.hiddenField.value;
						searchDs.removeAll();
						searchDs.baseParams = {
							cmd : 'search',
							action : 'searchPreview',
							json : Ext.util.JSON.encode(json),
							sc : BestvSearch.sc
						};
						searchDs
								.load({
									params : {
										start : 0,
										limit : 12,
										acs_type : 'keysubject'
									},
									callback : function(r, options, success) {
										if (searchDs.reader.jsonData == '') {
											Ext.MessageBox
													.alert(
															TXT_common_hint,
															TXT_common_relogin,
															function() {
																window.location.href = '../eni/common/logout.jsp';
															});
											return;
										}
									}
								});
					});
	var btnClear = new Ext.Button({
		text : TXT_common_reset,
		tooltip : TXT_common_reset,
		iconCls : 'icoDel'
	});
	btnClear.on('click', function() {
		searchInfoForm.getForm().reset();
	});
	var btnReturn = new Ext.Button({
		text : TXT_common_return,
		tooltip : TXT_common_return,
		iconCls : 'icoOut'
	});
	btnReturn.on('click', function() {
		selectKeyCache = '';
		kwin.close();
	});
	var searchDs = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : DISPATCH_URL
		}),
		reader : new Ext.data.JsonReader({
			root : 'results',
			totalProperty : 'totalCount',
			id : 'id',
			fields : [ {
				name : 'id'
			}, {
				name : 'name'
			}, {
				name : 'keywords'
			}, {
				name : 'type'
			}, {
				name : 'p_type'
			}, {
				name : 'updateTime'
			} ]
		})
	});

	var searchSm = new Ext.grid.CheckboxSelectionModel();
	var searchCm = new Ext.grid.ColumnModel([
			new Ext.grid.RowNumberer(),
			searchSm,
			{
				header : TXT_info_name,
				dataIndex : 'name',
				width : 150,
				renderer : function(v) {
					if (v.length > 6)
						return "<div ext:qtip='" + v + "'>" + v.substring(0, 6)
								+ "..." + "</div>";
					else
						return v;
				}
			},
			{
				header : '关键字',
				dataIndex : 'keywords',
				width : 280,
				renderer : function(v) {
					if (v.length > 15)
						return '<div qtip=' + v + '>' + v.substring(0, 15)
								+ '</div>';
					return v;
				}
			},
			{
				header : TXT_info_type,
				dataIndex : 'type',
				width : 65,
				renderer : function(v) {
					if (v.length > 3)
						return '<div qtip=' + v + '>' + v.substring(0, 3)
								+ '</div>';
					return v;
				}
			},
			{
				header : TXT_info_p_type,
				dataIndex : 'p_type',
				width : 78,
				renderer : function(v) {
					if (v.length > 4)
						return '<div qtip=' + v + '>' + v.substring(0, 4)
								+ '</div>';
					return v;
				}
			}, {
				header : '更新时间',
				dataIndex : 'updateTime',
				width : 105,
				renderer : function(v) {
					return v.substring(0, 10);
				}
			} ]);
	var searchGrid = new Ext.grid.GridPanel({
		border : false,
		height : 325,
		ds : searchDs,
		cm : searchCm,
		sm : searchSm,
		stripeRows : true,
		viewConfig : {
			forceFit : true
		},
		tbar : [ btnFind, '-', btnClear, '-', btnReturn, '-' ],
		loadMask : true,
		bbar : new Ext.PagingToolbar({
			pageSize : 12,
			height : 22,
			store : searchDs,
			displayInfo : true,
			displayMsg : TXT_common_paging,
			emptyMsg : TXT_common_no
		})
	});

	var nav = new Ext.Panel(
			{
				title : '关键字展示/选择',
				region : 'east',
				split : true,
				width : 210,
				height : 500,
				collapsible : false,
				autoScroll : true,
				buttonAlign : 'center',
				buttons : [ {
					text : TXT_common_OK,
					handler : function(response, options) {
						if (selectKeyCache == '') {
							Ext.MessageBox.confirm(TXT_common_hint,
									'您没有选择任何关键字,确定需要返回吗?', function(btn) {
										if (btn == 'yes') {
											kwin.close();
											return;
										}
										selectKeyCache = '';
									});
							return;
						}
						selectKeyCache = selectKeyCache.substring(2,
								selectKeyCache.length - 2);
						var selectKeys = selectKeyCache.split('/&/&');
						var keybody = document.getElementById('selectKeys').innerHTML;
						for ( var k = 0; k < selectKeys.length; ++k) {
							if (document.getElementById('s_' + selectKeys[k]) == null)
								keybody += '<span id=\'s_'
										+ selectKeys[k]
										+ '\'><u>'
										+ selectKeys[k]
										+ '<span class="delXO hV hM" onclick="deleteKey(\''
										+ selectKeys[k]
										+ '\')" style="background-color: rgb(238, 238, 238); color: rgb(34, 34, 34);"><span class="hO" title="删除">X</span></span></u></span>';
						}
						document.getElementById('selectKeys').innerHTML = keybody;
						selectKeyCache = '/&' + selectKeyCache + '/&';
						clearSelectKeyCache = false;
						kwin.close();
					}
				} ]
			});
	// nav.on('render',function(pl){
	// alert('render');
	// if(selectKeyCache == '') return;
	// var temp = selectKeyCache.substring(2,selectKeyCache.length -
	// 2).split('/&/&');
	// for(var k = 0; k < temp.length; ++k){
	// if(temp[k] == '') continue;
	// pl.add(new Ext.form.Checkbox({
	// hideLabel:true,
	// labelWidth:0,
	// checked:true,
	// height:20,
	// boxLabel: temp[k],
	// id: temp[k],
	// listeners:{
	// 'check':function(box,checked){
	// if(!checked){
	// if(selectKeyCache.indexOf('/&'+box.getId()+'/&')>=0)
	// selectKeyCache = selectKeyCache.replace('/&'+box.getId()+'/&','');
	// }else{
	// if(selectKeyCache.indexOf('/&'+box.getId()+'/&')< 0)
	// selectKeyCache += '/&'+box.getId()+'/&';
	// }
	// }}
	// }));
	// }
	// pl.doLayout();
	// });
	searchSm.on('rowselect', function(sm, index, record) {
		var newKey = record.get('keywords');
		if (newKey == '')
			return;
		var keys = newKey.split(' ');
		for ( var k = 0; k < keys.length; ++k) {
			if (nav.findById(keys[k]) == null)
				nav.add(new Ext.form.Checkbox(
						{
							hideLabel : true,
							labelWidth : 0,
							checked : true,
							height : 20,
							boxLabel : keys[k],
							id : keys[k],
							listeners : {
								'check' : function(box, checked) {
									if (!checked) {
										if (selectKeyCache.indexOf('/&'
												+ box.getId() + '/&') >= 0)
											selectKeyCache = selectKeyCache
													.replace('/&' + box.getId()
															+ '/&', '');
									} else {
										if (selectKeyCache.indexOf('/&'
												+ box.getId() + '/&') < 0)
											selectKeyCache += '/&'
													+ box.getId() + '/&';
									}
								}
							}
						}));
			else if (nav.findById(keys[k]).setValue(true))
				;
			if (selectKeyCache.indexOf('/&' + keys[k] + '/&') >= 0)
				continue;
			selectKeyCache += '/&' + keys[k] + '/&';
		}
		nav.doLayout();
	});
	searchSm.on('rowdeselect', function(sm, index, record) {
		var newKey = record.get('keywords');
		if (newKey == '')
			return;
		var keys = newKey.split(' ');
		for ( var k = 0; k < keys.length; ++k) {
			if (nav.findById(keys[k]) != null)
				nav.remove(keys[k], true);
			if (selectKeyCache.indexOf('/&' + keys[k] + '/&') < 0)
				continue;
			selectKeyCache = selectKeyCache.replace('/&' + keys[k] + '/&', '');
		}
		nav.doLayout();
	});

	var searchInfoForm = null;
	searchInfoForm = new Ext.FormPanel(
			{
				labelAlign : 'right',
				border : false,
				region : 'center',
				labelWidth : 75,
				width : 660,
				height : 500,
				// layout:'column',
				frame : true,
				items : [ {
					// columnWidth: 1.0,
					layout : 'column',
					items : [
							{
								columnWidth : 1.0,
								layout : 'form',
								defaultType : 'textfield',
								defaults : {
									anchor : '99%'
								},
								items : [
										new Ext.form.TextField(
												{
													fieldLabel : '<b style="color:red;">* </b> 关键字',
													id : 'skey',
													name : 'skey',
													listeners : {
														specialkey : function(
																field, e) {
															if (e.getKey() == e.ENTER) {
																if (!searchInfoForm
																		.getForm()
																		.isValid()) {
																	Ext.MessageBox
																			.alert(
																					TXT_common_hint,
																					'输入有误，请检查！');
																	return;
																}
																btnFind
																		.fireEvent('click');
															}
														}
													}
												}), searchFieldCombo,
										searchTypeCombo, vTypeCombo ]
							}, {
								columnWidth : 1.0,
								layout : 'column',
								items : [ {
									columnWidth : .4,
									layout : 'form',
									items : [ timeFrom ]
								}, {
									columnWidth : .02,
									layout : 'form',
									html : '~'
								}, {
									columnWidth : .4,
									layout : 'form',
									items : [ timeTo ]
								} ]
							}, {
								columnWidth : 1.0,
								layout : 'form',
								defaults : {
									anchor : '100%'
								},
								items : [ searchGrid ]
							} ]
				} ]
			});
	// end form
	var kwin = null;
	if (!kwin) {
		kwin = new Ext.Window({
			title : TXT_search_key,
			width : 860,
			height : 510,
			plain : true,
			layout : 'border',
			autoScroll : false,
			border : false,
			minimizable : false,
			maximizable : false,
			resizable : false,
			modal : true,
			layoutConfig : {
				animate : false
			},
			items : [ searchInfoForm, nav ]
		});
	}
	kwin.on('close', function() {
		if (clearSelectKeyCache)
			selectKeyCache = '';
		clearSelectKeyCache = true;
	});
	kwin.on('show', function() {
		if (selectKeyCache != '')
			clearSelectKeyCache = false;
	});
	kwin.show();
}
function deleteKey(key) {
	document.getElementById('selectKeys').removeChild(
			document.getElementById('s_' + key));
	selectKeyCache = selectKeyCache.replace('/&' + key + '/&', '');
}
Ext.onReady(displayKeySubject);